var state = false;
var enable = true;
var page = 2;

function bottomInfinite(){
    if(page){
        $("#home-stream-loading").slideDown(function(){
            $.get(base_url+'home/next_page/'+page, function(data) {
                $('#last-anchor').before(data);
                //$("#main-container").width(count());
                if(data.length > 10){
                    page++;
                }else{
                    page = false;
                }
                state=false;
                $("#home-stream-loading").slideUp();
            });
        });
    }else{
        $("#home-stream-loading").hide();
    }
}

function count(){
    total =  $(".home-column").size();
    return (total*360)+70;
}

/*
$(document).ready(function(){
    $("#main-container").width(count());
    $(window).scroll(function () { 
        if ($(window).scrollLeft() >= $(document).width() - $(window).width()-20) {
            if(!state){
                state=true;
                rightInfinite();
            }
        }
    });
});
*/

$(document).ready(function(){
    $(window).scroll(function () { 
        if ($(window).scrollTop() >= $(document).height() - $(window).height()-10) {
            if(!state && enable && page){
                state=true;
                bottomInfinite();
            }
        }
    });
});